static mut PRIME_LIST: Vec<u64> = Vec::new();

pub fn goldbach_conjecture() -> u64 {
    unsafe {
        PRIME_LIST.push(2);
        PRIME_LIST.push(3);
    }
    let mut res0 = 0;
    for i in (5..=u64::MAX).step_by(2) {
        if is_prime(i) {
            unsafe {
                PRIME_LIST.push(i);
            }
        } else if !is_goldbach_conjecture_correct(i) {
            res0 = i;
            break;
        }
    }
    let mut res1 = 0;
    for i in (res0 + 2..=u64::MAX).step_by(2) {
        if is_prime(i) {
            unsafe {
                PRIME_LIST.push(i);
            }
        } else if !is_goldbach_conjecture_correct(i) {
            res1 = i;
            break;
        }
    }
    unsafe { PRIME_LIST.clear(); }
    res0 + res1
}

/// 判断是否符合哥德巴赫猜想
#[inline(always)]
fn is_goldbach_conjecture_correct(i: u64) -> bool {
    for j in unsafe { PRIME_LIST.iter() } {
        let k = (((i - j) / 2) as f64).sqrt();
        if k == k.floor() {
            return true;
        }
    }
    false
}

/// 不安全判断 条件：` n > 3 || n % 2 != 0 `
#[inline(always)]
fn is_prime(n: u64) -> bool {
    if n % 3 == 0 {
        return false;
    }
    let mut i = 5;
    while i * i <= n {
        if n % i == 0 || n % (i + 2) == 0 {
            return false;
        }
        i += 6;
    }
    true
}
